package xyz.chaobei.thread.simple;

/**
 * @copyright (C), 2015-2020
 * @fileName: AddThread
 * @author: MRC
 * @date: 2021/1/26 20:52
 * @description:
 */
public class AddThread {

    /**
     * 这个类用来测试没有锁状态下的两个线程修改同一个变量的结果
     * @param args
     */
    public static void main(String[] args) {
        ThreadA a = new ThreadA();
        ThreadB b = new ThreadB();

        a.start();
        b.start();
    }
}

class Constants {
    public static int count = 0;
}

class ThreadA extends Thread {
    @Override
    public void run() {
        for (int i = 0; i <= 1000; i++) {
            Constants.count++;
        }
        System.out.println("ThreadA is end val=" + Constants.count);
    }
}

class ThreadB extends Thread {
    @Override
    public void run() {
        for (int i = 0; i <= 1000; i++) {
            Constants.count--;
        }
        System.out.println("ThreadB is end val=" + Constants.count);
    }
}
